/**
 *
 */
package vn.smartware.co.framework.db.factory;

import java.sql.Connection;
import java.sql.SQLException;


/**
 * JDBCFactory
 * 
 * @author thuctt
 */
public class JDBCFactory {

	/**
	 * Create new connection
	 * @return Connection
	 * @throws Exception 
	 * 
	 */
	public static Connection createConnection() throws Exception {

		DbResources dbResources = DbResources.getInstance();
		Connection con = dbResources.getDatasource().getConnection();
		con.setAutoCommit(false);
		return con;
	}

	/**`
	 * Commit data in current session
	 * 
	 * @param conn
	 * @throws SQLException
	 */
	public static void commit(Connection conn) throws SQLException {
		if (conn != null){
			conn.commit();
		}
	}

	/**
	 * Rollback current session
	 * 
	 * @param conn
	 * @throws SQLException
	 */
	public static void rollback(Connection conn) throws SQLException {
		if (conn != null){
			conn.rollback();
		}
	}

	/**
	 * Close current connection
	 * 
	 * @param conn
	 * @throws SQLException
	 */
	public static void closeConnection(Connection conn) throws SQLException {
		if (conn != null){
			conn.close();
		}
	}

}
